import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'
import HomePage from '../views/emp_page/HomePage.vue'
import ReportPage from '../views/emp_page/ReportPage.vue'
import DeptAudit from '../views/emp_page/DeptAudit.vue'
import AllReport from '../views/emp_page/AllReport.vue'
import AllFailReport from '../views/emp_page/AllFailReport.vue'
import EmpManage from '../views/admin_page/EmpManage.vue'
import ProjectManage from '../views/admin_page/ProjectManage.vue'
import DeptManage from '../views/admin_page/DeptManage.vue'

Vue.use(VueRouter)


const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/main',
    name: 'main',
    redirect: '/homePage/:job',
    component: Main,
    children: [
        {path: '/homePage/:job', name: 'homePage', component: HomePage},
        {path: '/deptAudit', name: 'deptAudit', component: DeptAudit},
        {path: '/allReport/:job', name: 'allReport', component: AllReport},
        {path: '/allFailReport/:job', name: 'allFailReport', component: AllFailReport},
        {path: '/reportPage', name: 'reportPage', component: ReportPage},
        {path: '/empManage', name: 'empManage', component: EmpManage},
        {path: '/projectManage', name: 'projectManage', component: ProjectManage},
        {path: '/deptManage', name: 'deptManage', component: DeptManage},
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(to.name != 'login' && sessionStorage.getItem("emp") == null) {
    next({name: 'login'})
  } else {
    next()//放行
  }
})

export default router
